﻿(function ($) {
    $.fn.selectAllToggle = function (option) {
        option = $.extend({
            target: null
        }, option);
        return this.each(function () {
            var view = $(this);
            var settings = $.extend({}, option);
            var container = view.closest("table");
            view.click(function () {
                if ($(this).attr("checked")) {
                    $(settings.target, container).attr("checked", true);
                } else {
                    $(settings.target, container).attr("checked", false);
                }
            });
        });
    };
})(jQuery);